package com.lanyun.aicorrectassistant.domain.aiModel.impl;

import com.lanyun.aicorrectassistant.basic.bean.PageResult;
import com.lanyun.aicorrectassistant.basic.entity.AiModel;
import com.lanyun.aicorrectassistant.basic.service.AiModelService;
import com.lanyun.aicorrectassistant.controller.admin.aiModel.vo.AiModelRequestPageVO;
import com.lanyun.aicorrectassistant.controller.admin.aiModel.vo.AiModelRequestVO;
import com.lanyun.aicorrectassistant.controller.admin.aiModel.vo.AiModelResponseVO;
import com.lanyun.aicorrectassistant.convert.AiModelConvert;
import com.lanyun.aicorrectassistant.domain.aiModel.AiModelDomainService;

import com.lanyun.aicorrectassistant.enums.IsDeletedFlagEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 大模型信息表（管理员维护）领域服务实现
 *
 * @author Jqchan
 * @version 1.0
 * @date 2025-05-29 23:26:28
 */
@Service
public class AiModelDomainServiceImpl implements AiModelDomainService {

    @Resource
    private AiModelService aiModelService;

    @Override
    public PageResult<AiModelResponseVO> page(AiModelRequestPageVO requestPageVO) {
        PageResult<AiModelResponseVO> pageResult = new PageResult<>();
        AiModel queryEntity = AiModelConvert.INSTANCE.convert(requestPageVO);
        queryEntity.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getVal());

        List<AiModel> entities = aiModelService.page(queryEntity,
                requestPageVO.getStart(), requestPageVO.getPageSize());

        if (entities.isEmpty()) {
            return pageResult;
        }

        Long count = aiModelService.count(queryEntity);
        List<AiModelResponseVO> vos = AiModelConvert.INSTANCE.convertEntityToRespList(entities);

        pageResult.setResult(vos);
        pageResult.setTotal(count.intValue());
        return pageResult;
    }

    @Override
    public Boolean update(AiModelRequestVO requestVO) {
        AiModel entity = AiModelConvert.INSTANCE.convert(requestVO);
        return aiModelService.update(entity) != 0;
    }

    @Override
    public Boolean delete(Integer id) {
        AiModel entity = new AiModel();
        entity.setId(id);
        entity.setIsDeleted(IsDeletedFlagEnum.DELETED.getVal());
        return aiModelService.update(entity) != 0;
    }

    @Override
    public Boolean insert(AiModelRequestVO requestVO) {
        AiModel entity = AiModelConvert.INSTANCE.convert(requestVO);
        return aiModelService.insert(entity) != 0;
    }

    @Override
    public AiModelResponseVO get(Integer id) {
        AiModel entity = aiModelService.queryById(id);
        return AiModelConvert.INSTANCE.convert(entity);
    }
}
